﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Skynet.WebFoundation.Controls.Runtime
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:BoolAlternativeControl runat=server></{0}:BoolAlternativeControl>")]
    public class BoolAlternativeControl : CompositeControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public Guid? AlternativeCustomerId
        {
            get
            {
                return (Guid?)ViewState["AlternativeCustomerId"];
            }
            set
            {
                ViewState["AlternativeCustomerId"] = value;
            }
        }
        public bool? Answer
        {
            get
            {
                if (!this._yb.Checked && !this._nb.Checked)
                    return null;
                else if (this._yb.Checked)
                    return true;
                else
                    return false;                
            }
            set
            {
                if (!value.HasValue)
                {
                    this._yb.Checked = false;
                    this._nb.Checked = false;
                }
                else if (value == true)
                {
                    this._yb.Checked = true;
                    this._nb.Checked = false;
                }
                else if (value == false)
                {
                    this._yb.Checked = false;
                    this._nb.Checked = true;
                }

            }
        }
        private CheckBox _yb = new CheckBox() { Text = "yes" };
        private CheckBox _nb = new CheckBox() { Text = "no" };
        protected override void CreateChildControls()
        {
            this._yb.SkinID = this.SkinID;
            this._nb.SkinID = this.SkinID;
            this.Controls.Add(_yb);
            this.Controls.Add(_nb);
        }   
    }
}
